/**
 * Copyright:Copyright(c)2014-2017
 * Company:厦门市易致达物联网科技有限公司
 * @version 1.0
 */
package shop.controller.front.rank;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import shop.core.FrontBaseController;
import shop.core.Services;
import shop.core.common.bean.JSONResult;
import shop.services.front.rank.RankService;
import shop.services.front.rank.bean.Rank;
import shop.services.manage.system.bean.User;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.math.BigDecimal;
import java.util.List;

/**
 * @类名称：RankController
 * @创建人：Wzl
 * @创建时间：2017-10-13 下午16:10:42
 * @版本号：1.0
 * @描述：商家等级
 */
@Controller
@RequestMapping("/front/rank/")
public class RankController extends FrontBaseController<Rank> {
    @Resource
    private RankService rankService;
    @Override
    public Services<Rank> getService() {
        return rankService;
    }

    /**
     * 跳转到等级列表页面
     *
     * @return
     */
    @RequestMapping("toRankList")
    public String toRankList() {
        return "/front/seller/memberGrade";
    }

    /**
     * 查询等级列表
     *
     * @return
     * @throws Exception
     */
    @RequestMapping("selectRankList")
    @ResponseBody
    public JSONResult selectRankList(HttpSession session,Rank rank) throws Exception {
        User user = (User) session.getAttribute("userInfo");
        List<Rank> rsList = rankService.selectRankList(rank);
        for(Rank rankInfo :rsList){
            if(user.getRankID().equals(rankInfo.getId())){
                rankInfo.setIsNow("y");
            }else{
                rankInfo.setIsNow("n");
            }
        }
        jsonResult = new JSONResult();
        jsonResult.setData(rsList);
        return jsonResult;
    }

    /**
     * 查询分销商优惠比例
     *
     * @param
     * @return
     */
    @RequestMapping(value = "selectRankPercent", method = RequestMethod.GET)
    @ResponseBody
    public JSONResult selectRankPercent(HttpSession session) {
        User user = (User) session.getAttribute("userInfo");
        Rank rank =new Rank();
        rank.setId(user.getRankID());
        rank=rankService.selectOne(rank);
        BigDecimal percent =rank.getPercent();
        jsonResult = new JSONResult();
        jsonResult.setData(percent);
        return jsonResult;
    }
}
